/******************************************************************************
* This file is part of is32p218 platform,
* Copyright (c) 2009 HangZhou InfoStrong CO.,LTD. All rights reserved.
* This software may only be used under the terms of a valid, current,
* end user license from InfoStrong.
* Nothing else gives you the right to use this software.   
*
* Name:   plc.h
* Desc:   PLC Module main header file
* Author: Jerry
* Date:   2009-10-27
* Note:   
* History:
*
******************************************************************************/
#include "def.h"

#include "plc_if.h"

#ifndef __PLC_H__
#define __PLC_H__

#ifdef __cplusplus
extern "C" {
#endif

#define BUILD_NET_BC		1
#define BUILD_NET_MAC_RELAY	2
#define BUILD_NET_MAC		3

#define PLC_BUILD_NET		BUILD_NET_BC

typedef enum
{
	// MSG PLC IF to PLC message
	MSG_PLCIF_TO_HL = 0x100,			// PLC if to PLC HL
	MSG_PLCIF_TO_HL_DATA,				// PLC if to PLC HL data
	MSG_PLCIF_TO_HL_STAT,				// PLC if status
	MSG_PLCIF_TO_HL_DEBUG,				// Debug message
	MSG_PLCIF_TO_HL_ERR,				// PLC if error
	//MSG_PLCIF_TO_HL_TMOUT,				// PLC if time out
#ifdef PLC_MAC_BIND
	MSG_PLCIF_TO_HL_BIND_MAC,			// Bind MAC Message
	MSG_PLCIF_TO_HL_BIND_MAC_MONI,		// Bind MAC monitor Message
#endif
#ifdef EVENT_REPORT
	MSG_PLCIF_TO_HL_EVENT_REPORT,		// Event report
	MSG_PLCIF_TO_HL_EVENT_REPORT_MONI,	// Event report monitor
#endif
	MSG_PLCIF_TO_HL_DL_NORMAL_BUSY,		// DL Normal channel busy status
	MSG_PLCIF_TO_HL_DL_NORMAL_IDLE,		// DL Normal channel idle status
#ifdef UPDATE_SW_FLG
	MSG_PLCIF_TO_HL_UPDATE_SW,			// Update SW
#endif
	
	// MSG APP to PLC message
	MSG_AFN_TO_PLC = 0x200,
	MSG_AFN_TO_PLC_INIT,				// Init and start PLC
	MSG_AFN_TO_PLC_SEND,				// Send Data
	MSG_AFN_TO_PLC_ACK,					// PLC ACK

#if defined(PLC_MAC_BIND)||defined(PLC_VOID_COLLUDE)
	MSG_AFN_TO_PLC_REG_SET,				// Reg set
#endif										
#ifdef EVENT_REPORT											
#ifdef MASTER_NODE											
	MSG_AFN_TO_PLC_REG_ACTIVE,			// Register active
	MSG_AFN_TO_PLC_EVENT_ACK,			// Event-report ACK (M)
#else										
	MSG_AFN_TO_PLC_EVENT,				// Event-data message (S)
#endif
#endif
	MSG_AFN_TO_PLC_DEBUG,				// Remote debug through PLC channel
#ifdef UPDATE_SW_FLG
	MSG_AFN_TO_PLC_UPDATE_SW,			// REPORT (M)
#endif
#ifdef PING_MT_FLG
	MSG_AFN_TO_PLC_PING_MT_RSP,			// Ping MT response
#endif	
	// MSG PLC to PLC message
	MSG_PLC_TO_PLC = 0x400,
	MSG_PLC_TO_PLC_SND_TMOUT,			// Send timeout
#if defined(MASTER_NODE)&&defined(PLC_DC_THREE_CHIPS)
	MSG_PLC_TO_PLC_SIGNAL_CLR,			// Clear Signal
#endif	

#if defined(MASTER_NODE)&&(defined(PLC_VOID_COLLUDE)||defined(PLC_MAC_BIND))
	MSG_PLC_TO_PLC_CLR_DC_MAC,			// CLR DC MAC (M)
#endif
	
#if (defined(MASTER_NODE)&&defined(PLC_VOID_COLLUDE))||defined(PLC_MAC_BIND)
	MSG_PLC_TO_PLC_MAC_BIND_START,		// MAC Bind Start
#endif

#ifdef PLC_MAC_BIND								
	MSG_PLC_TO_PLC_MAC_BIND_T1_TMOUT,	// Timer<Timer out>: Master wait for Keep-command of other DCs (M)
#ifdef MASTER_NODE
	MSG_PLC_TO_PLC_MAC_BIND_CMD,		// Bind MAC Cmd (M)
	MSG_PLC_TO_PLC_MAC_BIND_T2_TMOUT,	// Timer<Timer out>: Master wait for report message of slave (M)
	MSG_PLC_TO_PLC_MAC_BIND_S_INFO_CFM_TMOUT,	// Timer<Timer out>: S-info comfirm time-out of Slave
	MSG_PLC_TO_PLC_MAC_BIND_END,		// Bind MAC end	(M)
#else										
//	MSG_PLC_TO_PLC_MAC_BIND_KEEP,		// Bind MAC keep (S)
	MSG_PLC_TO_PLC_MAC_BIND_SLOT_TMOUT,	// Timer<Timer out>: Slot-time of slave (S)
	MSG_PLC_TO_PLC_MAC_BIND_REQ_SND,	// Bind MAC request message send (S)
	MSG_PLC_TO_PLC_MAC_BIND_S_INFO_RSP_TMOUT,	// Timer<Timer out>: S-info rsponse time-out of DC (S)
	MSG_PLC_TO_PLC_MAC_BIND_START_TMOUT,	// Slave node start timeout
#endif
#endif

	// MSG IDLE to PLC_HL message
	MSG_IDLE_TO_PLC_HL = 0x800,
	MSG_PLC_END
}MSG_PLC_T;

#define PLC_MSG_BUFF_SIZE	256

typedef PLC_IF_PARAMS PLC_PARAMS_T;
typedef PLC_IF_MASTER_PARAMS PLC_MASTER_PARAMS_T;

void plc_module_init( void );
BOOL plc_msg_snd( U16 msg_id, U8 *p_msg_data, U16 msg_len );
BOOL plc_main_que_empty( void );

#ifdef __cplusplus
}
#endif

#endif // end __PLC_H__

